#include "wopDrawing2D.h"
#include "wopColorRGBA.h"
#include "wopVector3f.h"

#include <math.h>

#include <GL/glew.h>

void wopDrawing2D::drawCircle(float radius, const wopColorRGBA& color)
{
	glColor4f(color.r, color.g, color.b, color.a);
	glBegin(GL_TRIANGLE_FAN);
		glVertex2f(0.0f, 0.0f);
		for (float _angle = 0.f; _angle < 360.f; _angle+=0.1f)
		{
			glVertex2f(sinf(_angle) * radius, cosf(_angle) * radius);
		}
	glEnd();
}

void wopDrawing2D::drawTriangle(const wopVector3f& base_point_left, const wopVector3f& base_point_right, const wopVector3f& top_point, const wopColorRGBA& color)
{
	glColor4f(color.r, color.g, color.b, color.a);
	glBegin(GL_TRIANGLES);
		glVertex3f(base_point_left.x, base_point_left.y, base_point_left.z);
		glVertex3f(base_point_right.x, base_point_right.y, base_point_right.z);
		glVertex3f(top_point.x, top_point.y, top_point.z);
	glEnd();
}

void wopDrawing2D::drawSquare(const float size, const wopColorRGBA& color)
{
	drawRectangle(size, size, color);
}

void wopDrawing2D::drawSquareTextured(const float size)
{
	drawRectangleTextured(size, size);
}
	
void wopDrawing2D::drawRectangle(const float width, const float height, const wopColorRGBA& color)
{
	glColor4f(color.r, color.g, color.b, color.a);
	glBegin(GL_QUADS);
		glVertex3f(0.0f, 0.0f, 0.0f);
		glVertex3f(width, 0.0f, 0.0f);
		glVertex3f(width, height, 0.0f);
		glVertex3f(0.0f, height, 0.0f);
	glEnd();
}

void wopDrawing2D::drawRectangleTextured(const float width, const float height)
{
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f);
		glVertex3f(0.0f, 0.0f, 0.0f);

		glTexCoord2f(1.0f, 0.0f);
		glVertex3f(width, 0.0f, 0.0f);

		glTexCoord2f(1.0f, 1.0f);
		glVertex3f(width, height, 0.0f);

		glTexCoord2f(0.0f, 1.0f);
		glVertex3f(0.0f, height, 0.0f);
	glEnd();
}